//
//  MemberCenterViewController.m
//  minfubaoLib
//
//  Created by 钱坚 on 15/11/9.
//  Copyright © 2015年 苏州鱼儿信息科技有限公司. All rights reserved.
//
#import "MemberCenterViewController.h"
#import "UINavigationBar+Awesome.h"
#import "MySelfInfoViewController.h"
#import "FeedBackViewController.h"
#import "AboutViewController.h"
#import "UIImageView+WebCache.h"
#import "WebViewController.h"
#import "SettingsViewController.h"
#import "LoginViewController.h"

@interface MemberCenterViewController (){

    MemberInfoDataModel *memberinfodatamodel;
    menuMemberCenterListInfoModel *message;
    NSMutableArray *first_array;
    NSMutableArray *second_array;
    NSMutableArray *third_array;
}
@end

@implementation MemberCenterViewController
@synthesize myScrollView,headIconView,nameLabel,sexImageView,getData,talkCount,balance,focusTeacherNum,headView,headBgImg,headViewHeight;

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view setBackgroundColor:[UIColor whiteColor]];
    self.title = @"个人中心";

    [self setCustomRightButtonWithNum:self action:@selector(rightclick:) img:@"icon_xiaoxi_2x"];
    
    CGFloat tabbarH = 0;
    if (!self.rdv_tabBarController.isTabBarHidden) {
        tabbarH = CGRectGetHeight(self.rdv_tabBarController.tabBar.frame);
    }
    
    CGFloat bottom = 0;
    
    headViewHeight = kScreenW*0.6;
    
    myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, bottom, self.view.frame.size.width, self.view.frame.size.height-bottom-tabbarH)];
    
    [myScrollView setBackgroundColor:[utils getBackGroupColorGray]];
    myScrollView.showsHorizontalScrollIndicator = NO;
    myScrollView.showsVerticalScrollIndicator = FALSE;
    myScrollView.delegate = self;
    myScrollView.contentInset = UIEdgeInsetsMake(headViewHeight, 0, 0, 0);
    
    [self.view addSubview:myScrollView];
    [self initView];
}

-(IBAction)rightclick:(id)sender{
    
    NSString *token = [utils getString:TOKEN];
    if (token && ![token isEqualToString:@""]) {
        
        if (message && message.url && ![message.url isEqualToString:@""]) {
            if ([(AppDelegate *)[UIApplication sharedApplication].delegate isConnectionAvailable]) {
                WebViewController *view = [[WebViewController alloc] initWithUrl:message.url withTitle:nil];
                [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
                [self.navigationController pushViewController:view animated:YES];
            }
        }
        
    }else{
        
        LoginViewController *view = [[LoginViewController alloc] init];
        [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
        [self.navigationController pushViewController:view animated:YES];
        
    }

}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
    
    [self.navigationController.navigationBar lt_setBackgroundColor:[UIColor clearColor]];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    
    [self getContent];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    [self.navigationController.navigationBar lt_setBackgroundColor:[utils getThemeColor]];
    [self.navigationController.navigationBar setShadowImage:nil];
}

- (void)getContent{
    
     __weak typeof(self) weakSelf = self;
    [HttpNetWorkUtil requestgetMemberInfo:nil success:^(id json) {
         __strong __typeof(weakSelf)strongSelf = weakSelf;
        
        memberinfodatamodel = [[MemberInfoDataModel alloc] init];
        [memberinfodatamodel fillWithJsonDict:json];
        
        first_array = [[NSMutableArray alloc] init];
        second_array = [[NSMutableArray alloc] init];
        third_array = [[NSMutableArray alloc] init];
        for (int i=0; i<memberinfodatamodel.infomodel.menuMemberCenterList.count; i++) {
            menuMemberCenterListInfoModel *menu = [memberinfodatamodel.infomodel.menuMemberCenterList objectAtIndex:i];
            
            if ([menu.menuType isEqualToString:@"1"]) {
                message = menu;
            }else if([menu.menuType isEqualToString:@"2"]){
                [first_array addObject:menu];
            }else if([menu.menuType isEqualToString:@"3"]){
                [second_array addObject:menu];
            }else if([menu.menuType isEqualToString:@"4"]){
                [third_array addObject:menu];
            }
        }
        

        
        menuMemberCenterListInfoModel *menu = [[menuMemberCenterListInfoModel alloc] init];
        menu.icon =@"http://58.211.5.134:8080/imgShare/images/upload/businessPath/493e996ee94ba9ac9d375d350d2416de.png";
        menu.menuDesc = @"";
        menu.menuName = @"系统设置";
        [third_array addObject:menu];
        
        [strongSelf initView];
        
        
    } fail:^{}];
}

- (void)initView{
    [myScrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    [self setCustomRightButtonWithNum:self action:@selector(rightclick:) img:message.icon];
    
    NSInteger readnum = [[utils getString:MSG_NUM] integerValue];
    NSInteger totalnum = [memberinfodatamodel.infomodel.msgCount integerValue];
    NSUInteger unreadnum =  totalnum-readnum;
    [self setNum:unreadnum];
    
    CGFloat y = [self initHeadView];
    
    y = [self initMiddleView:y] + 10;
    
    y = [self initSecondView:y]+10;
    y = [self initThirdView:y];
    
    self.myScrollView.contentSize = CGSizeMake(1,y);
}

- (CGFloat)initHeadView{
    headView = [[UIView alloc]initWithFrame:CGRectMake(0, -headViewHeight, self.view.frame.size.width, headViewHeight)];

    [headView setBackgroundColor:[UIColor clearColor]];
    headBgImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, -headViewHeight, self.view.frame.size.width, headViewHeight)];
    [headBgImg setImage:[UIImage imageNamed:@"bg_2x"]];
    [myScrollView addSubview:headBgImg];
    
    CGFloat headIconSize = headViewHeight/3;
    CGFloat headIconX = self.view.frame.size.width/2 - headIconSize/2;
    CGFloat headIconY = headViewHeight/2 - headIconSize/2;
    
    UIImageView *headIconView_bg = [[UIImageView alloc]initWithFrame:CGRectMake(headIconX-3, headIconY-3, headIconSize+6, headIconSize+6)];
    [headIconView_bg setBackgroundColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.3]];
    headIconView_bg.layer.cornerRadius = headIconView_bg.frame.size.width / 2;
    headIconView_bg.clipsToBounds = YES;
    headIconView_bg.layer.masksToBounds = YES;
    [headView addSubview:headIconView_bg];
    
    headIconView = [[UIImageView alloc]initWithFrame:CGRectMake(headIconX, headIconY, headIconSize, headIconSize)];
    [headIconView sd_setImageWithURL:[NSURL URLWithString:memberinfodatamodel.infomodel.m.headPic] placeholderImage:[UIImage imageNamed:@"touxiang_2x"] options:SDWebImageRefreshCached|SDWebImageContinueInBackground|SDWebImageRetryFailed];
    headIconView.layer.cornerRadius = headIconView.frame.size.width / 2;
    headIconView.clipsToBounds = YES;
    headIconView.layer.masksToBounds = YES;
    [headView addSubview:headIconView];
    headIconView.userInteractionEnabled = YES;
    UITapGestureRecognizer *headIconViewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(headIconClick:)];
    [headIconView addGestureRecognizer:headIconViewTap];
    
    UIView *tel_view = [[UIView alloc] init];
    
    NSString *token = [utils getString:TOKEN];
    if (token && ![token isEqualToString:@""]) {
        UIImage *sexImge = [UIImage imageNamed:@"icon_shouji_2x"];
        sexImageView = [[UIImageView alloc]initWithImage:sexImge];
        sexImageView.frame = CGRectMake(10, 2, 20, 20);
        [tel_view addSubview:sexImageView];
        
        nameLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        nameLabel.text = memberinfodatamodel.infomodel.m.phone;
        nameLabel.textColor = [UIColor whiteColor];
        nameLabel.font = [UIFont systemFontOfSize:16];
        [nameLabel sizeToFit];
        nameLabel.frame = CGRectMake( [utils getViewRight:sexImageView] + 3, 0, nameLabel.frame.size.width, 24);
        [tel_view addSubview:nameLabel];
        
        CGFloat tel_view_w = [utils getViewRight:nameLabel] + 10;
        [tel_view setFrame:CGRectMake( (kScreenW-tel_view_w)/2, [utils getViewBottom:headIconView] + OFFSET_TWN, tel_view_w, 24)];
        UIImageView *telbg_view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, tel_view.frame.size.width, tel_view.frame.size.height)];
        [telbg_view setImage:[UIImage imageNamed:@"shoujihao_2x"]];
        [tel_view addSubview:telbg_view];
        [tel_view sendSubviewToBack:telbg_view];
    }else{
        
        nameLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        nameLabel.text = @"登录/注册";
        nameLabel.textColor = [UIColor whiteColor];
        nameLabel.font = [UIFont systemFontOfSize:16];
        [nameLabel sizeToFit];
        nameLabel.frame = CGRectMake( 10, 0, nameLabel.frame.size.width, 24);
        [tel_view addSubview:nameLabel];
        
        CGFloat tel_view_w = [utils getViewRight:nameLabel] + 10;
        [tel_view setFrame:CGRectMake( (kScreenW-tel_view_w)/2, [utils getViewBottom:headIconView] + OFFSET_TWN, tel_view_w, 24)];
        
        nameLabel.userInteractionEnabled = YES;
        UITapGestureRecognizer *nameViewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(headIconClick:)];
        [nameLabel addGestureRecognizer:nameViewTap];
    }

    [headView addSubview:tel_view];
    
    [myScrollView addSubview:headView];
    
    return [utils getViewBottom:headView];
}

- (void)headIconClick:(UIGestureRecognizer *)gestureRecognizer {
    NSString *token = [utils getString:TOKEN];
    if (token && ![token isEqualToString:@""]) {
        
        MySelfInfoViewController *view = [[MySelfInfoViewController alloc]initWithInfo:memberinfodatamodel];
        [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
        [self.navigationController pushViewController:view animated:YES];
        
    }else{
        
        LoginViewController *view = [[LoginViewController alloc] init];
        [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
        [self.navigationController pushViewController:view animated:YES];
        
    }
}

- (CGFloat)initMiddleView:(CGFloat)point_y{

    if (first_array.count>0) {
        
        
        _middleView = [[UIView alloc] initWithFrame:CGRectMake(0, point_y, kScreenW, 44)];
        [_middleView setBackgroundColor:[UIColor whiteColor]];
        
        UIView *first = [self getMidSubView:CGRectMake(0, 0, _middleView.frame.size.width/2, _middleView.frame.size.height) withdata:[first_array objectAtIndex:0]];
        first.tag = 0;
        UITapGestureRecognizer *middleViewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(middleClick:)];
        [first addGestureRecognizer:middleViewTap];
        [_middleView addSubview:first];
        
        UIView *line =[[UIView alloc] initWithFrame:CGRectMake(_middleView.frame.size.width/2-1, 4, 1, 36)];
        line.backgroundColor = [utils getLineColorGray];
        [_middleView addSubview:line];
        
        if (first_array.count>1) {
            UIView *second = [self getMidSubView:CGRectMake(_middleView.frame.size.width/2, 0, _middleView.frame.size.width/2, _middleView.frame.size.height) withdata:[first_array objectAtIndex:1]];
            second.tag = 1;
            UITapGestureRecognizer *secondmiddleViewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(middleClick:)];
            [second addGestureRecognizer:secondmiddleViewTap];
            [_middleView addSubview:second];
        }
        
        [myScrollView addSubview:_middleView];
    }
    
    
    return [utils getViewBottom:_middleView];
}

-(UIView *)getMidSubView:(CGRect)rect withdata:(menuMemberCenterListInfoModel*)menu{
    UIView *view = [[UIView alloc] initWithFrame:rect];
    
    UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(5, 0, rect.size.height/3, rect.size.height)];
    imageview.contentMode = UIViewContentModeScaleAspectFit;
    UIImage *defualt_img;
    if (imageview.frame.size.height != imageview.frame.size.width) {
        defualt_img = [utils addImage:[UIImage imageNamed:@"default"] withsize:imageview.frame.size];
    }else{
        defualt_img = [UIImage imageNamed:@"default"];
    }
    [imageview sd_setImageWithURL:[NSURL URLWithString:menu.icon] placeholderImage:nil options:SDWebImageRefreshCached|SDWebImageContinueInBackground|SDWebImageRetryFailed];
    [view addSubview:imageview];
    
    UILabel *title = [utils getLabel:14 color:[utils getTextColorBlack]];
    title.text = menu.menuName;
    [title sizeToFit];
    title.frame = CGRectMake([utils getViewRight:imageview]+5, 0, title.frame.size.width, rect.size.height);
    [view addSubview:title];
    
    UILabel *content = [utils getLabel:14 color:[utils getButtonColor]];
    content.text = menu.menuDesc;
    [content sizeToFit];
    content.frame = CGRectMake([utils getViewRight:title]+15, 0, content.frame.size.width, rect.size.height);
    [view addSubview:content];

    CGFloat offset_x = (rect.size.width - [utils getViewRight:content]-5)/2;
    [imageview setMj_x:offset_x + imageview.frame.origin.x];
    [title setMj_x:offset_x + title.frame.origin.x];
    [content setMj_x:offset_x + content.frame.origin.x];
    
    return view;
}

- (void)middleClick:(UIGestureRecognizer *)gestureRecognizer {
    
    NSString *token = [utils getString:TOKEN];
    if (token && ![token isEqualToString:@""]) {
        
        UIView *view = [gestureRecognizer view];
        menuMemberCenterListInfoModel *menu = [first_array objectAtIndex:view.tag];
        
        if (menu && menu.url && ![menu.url isEqualToString:@""]) {
            if ([(AppDelegate *)[UIApplication sharedApplication].delegate isConnectionAvailable]) {
                WebViewController *view = [[WebViewController alloc] initWithUrl:menu.url withTitle:nil];
                [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
                [self.navigationController pushViewController:view animated:YES];
            }
        }else{
            
            [self showTip];
        }
        
    }else{
        
        LoginViewController *view = [[LoginViewController alloc] init];
        [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
        [self.navigationController pushViewController:view animated:YES];
        
    }
}

- (CGFloat)initSecondView:(CGFloat)point_y{
    
    if (second_array.count>0) {
        _SecondView = [[UIView alloc] initWithFrame:CGRectMake(0, point_y, kScreenW, 110)];
        [_SecondView setBackgroundColor:[UIColor whiteColor]];
        
        int num = 4;
        if (second_array.count<4) {
            num = (int)second_array.count;
        }
        
        CGFloat button_width = kScreenW/num;
        
        for (int i=0; i<num; i++) {
            
            menuMemberCenterListInfoModel *menu = [second_array objectAtIndex:i];
            UIControl *operButton = [self getOperButton:CGRectMake(button_width*i, 0, button_width, _SecondView.frame.size.height) withimg:menu.icon withname:menu.menuName];
            operButton.tag = i;
            [operButton addTarget:self action:@selector(secondButtonclick:) forControlEvents:UIControlEventTouchUpInside];
            [_SecondView addSubview:operButton];
        }
        
        [myScrollView addSubview:_SecondView];
    }
    return [utils getViewBottom:_SecondView];
}

-(UIControl*)getOperButton:(CGRect)rect withimg:(NSString*)img withname:(NSString*)name{
    
    UIControl *operButton = [[UIControl alloc] initWithFrame:rect];
    
    UILabel *opername = [utils getLabel:15 color:[utils getTextColorBlack]];
    opername.text =name ;
    opername.textAlignment = NSTextAlignmentCenter;
    [opername sizeToFit];
    
    CGFloat operButton_w = operButton.frame.size.width;
    CGFloat operButton_h = operButton.frame.size.height;
    CGFloat img_wh = operButton_h/3;
    UIImageView *imgview = [[UIImageView alloc] initWithFrame:CGRectMake((operButton_w-img_wh)/2, (operButton_h - (img_wh + opername.frame.size.height + 8))/2, img_wh, img_wh)];
//    [imgview setImage:[UIImage imageNamed:img]];
    UIImage *defualt_img;
    if (imgview.frame.size.height != imgview.frame.size.width) {
        defualt_img = [utils addImage:[UIImage imageNamed:@"default"] withsize:imgview.frame.size];
    }else{
        defualt_img = [UIImage imageNamed:@"default"];
    }
    [imgview sd_setImageWithURL:[NSURL URLWithString:img] placeholderImage:nil options:SDWebImageRefreshCached|SDWebImageContinueInBackground|SDWebImageRetryFailed];
    
    [opername setFrame:CGRectMake(0, [utils getViewBottom:imgview]+8, operButton_w, opername.frame.size.height)];
    
   
    [operButton addSubview:imgview];
    [operButton addSubview:opername];

    if (![name isEqualToString:@"商城足迹"]) {
        UILabel *line = [[UILabel alloc ] initWithFrame:CGRectMake(operButton_w, 0, 0.45, operButton_h)];
        line.backgroundColor = [UIColor lightGrayColor];
        [operButton addSubview:line];
    }
    
   
    return operButton;
}



-(void)showTip{
    DXAlertView *alert = [[DXAlertView alloc] initWithTitle:@"提示" contentText:@"\n开发中，敬请期待！" leftButtonTitle:nil rightButtonTitle:@"确认"];
    [alert show];
    alert.leftBlock = ^() {
    };
    alert.rightBlock = ^() {
      
    };
    alert.dismissBlock = ^() {

    };
}

-(IBAction)secondButtonclick:(id)sender{
    
    NSString *token = [utils getString:TOKEN];
    if (token && ![token isEqualToString:@""]) {
        
        UIView *view = (UIView*)sender;
        
        menuMemberCenterListInfoModel *menu = [second_array objectAtIndex:view.tag];
        
        if (menu && menu.url && ![menu.url isEqualToString:@""]) {
            if ([(AppDelegate *)[UIApplication sharedApplication].delegate isConnectionAvailable]) {
                WebViewController *view = [[WebViewController alloc] initWithUrl:menu.url withTitle:nil];
                [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
                [self.navigationController pushViewController:view animated:YES];
            }
        }else{
            
            [self showTip];
        }
        
    }else{
        
        LoginViewController *view = [[LoginViewController alloc] init];
        [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
        [self.navigationController pushViewController:view animated:YES];
        
    }
}

- (CGFloat)initThirdView:(CGFloat)point_y{
    
    _ThirdView = [[UIView alloc] initWithFrame:CGRectMake(0, point_y, kScreenW, 0)];
    [_ThirdView setBackgroundColor:[UIColor whiteColor]];
    
    CGFloat bottom = 0;
    for (int i=0 ; i<third_array.count; i++) {
        
        menuMemberCenterListInfoModel *menu = [third_array objectAtIndex:i];
        UIControl *thirditem ;
        if (i == 0 ) {
            thirditem = [self getThirdView:CGRectMake(0, bottom, _ThirdView.frame.size.width, 44) WithData:menu HaveArrow:YES isFirst:YES];
        }else{
            thirditem = [self getThirdView:CGRectMake(0, bottom, _ThirdView.frame.size.width, 44) WithData:menu HaveArrow:YES isFirst:NO];
        }
        
   
        thirditem.tag = i;
        [thirditem addTarget:self action:@selector(thirdButtonclick:) forControlEvents:UIControlEventTouchUpInside];
        [_ThirdView addSubview:thirditem];
        bottom +=44;
    }
    
    [_ThirdView setMj_h:bottom];
    [myScrollView addSubview:_ThirdView];
    
    return [utils getViewBottom:_ThirdView];
}

- (UIControl*)getThirdView:(CGRect)rect WithData:(menuMemberCenterListInfoModel*)menu HaveArrow:(BOOL)havearrow isFirst:(BOOL)isFirst {
    
    UIControl *item = [[UIControl alloc] initWithFrame:rect];
    [item setBackgroundColor:[UIColor whiteColor]];
    CGFloat right_offset = rect.size.width;
    
    if(havearrow) {
        UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(right_offset-35, 0, 30, rect.size.height)];
        imageview.contentMode = UIViewContentModeScaleAspectFit;
        [imageview setImage:[UIImage imageNamed:@"jinru_2x"]];
        [item addSubview:imageview];
        right_offset = imageview.frame.origin.x;
    }
    
    UILabel *title_label = [utils getLabel:14 color:[utils getTextColorBlack]];
    title_label.text = menu.menuName;
    title_label.textAlignment = NSTextAlignmentCenter;
    [title_label sizeToFit];
    title_label.frame = CGRectMake(10, 0, title_label.frame.size.width, rect.size.height);
    [item addSubview:title_label];
    
    if (menu.menuDesc) {
        UILabel *content = [utils getLabel:14 color:[utils getTextColorGray]];
        content.text = menu.menuDesc;
        content.textAlignment = NSTextAlignmentRight;
        content.frame = CGRectMake([utils getViewRight:title_label]+5, 0, right_offset-[utils getViewRight:title_label]-5, rect.size.height);
        [item addSubview:content];
    }
    
    UIView *lbl = [[UIView alloc] init]; //分割线
    lbl.frame = CGRectMake(0 , rect.size.height - 0.5, rect.size.width , 0.5);
    lbl.backgroundColor =  [utils getLineColorGray];
    [item addSubview:lbl];
    
    if (isFirst) {
        UIView *lblTop = [[UIView alloc] init]; //分割线
        lblTop.frame = CGRectMake(0 , 0, rect.size.width , 0.5);
        lblTop.backgroundColor =  [utils getLineColorGray];
        [item addSubview:lblTop];
    }
    
    [item addSubview:lbl];
    
    
    return item;
}

-(IBAction)thirdButtonclick:(id)sender{
    
    NSString *token = [utils getString:TOKEN];
    if (token && ![token isEqualToString:@""]) {
        
        UIView *view = (UIView*)sender;
        
        menuMemberCenterListInfoModel *menu = [third_array objectAtIndex:view.tag];
        
        if (menu && menu.url && ![menu.url isEqualToString:@""]) {
            if ([(AppDelegate *)[UIApplication sharedApplication].delegate isConnectionAvailable]) {
                WebViewController *view = [[WebViewController alloc] initWithUrl:menu.url withTitle:nil];
                [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
                [self.navigationController pushViewController:view animated:YES];
            }
        }else{
            if ([menu.menuName isEqualToString:@"系统设置"]) {
                SettingsViewController *view = [[SettingsViewController alloc] init];
                [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
                [self.navigationController pushViewController:view animated:YES];
                
            }
        }
        
    }else{
        
        LoginViewController *view = [[LoginViewController alloc] init];
        [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
        [self.navigationController pushViewController:view animated:YES];
        
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat yOffset  = scrollView.contentOffset.y;
    if (yOffset < -headViewHeight) {
        CGRect f = headBgImg.frame;
        f.origin.y = yOffset;
        f.size.height =  -yOffset;
        headBgImg.frame = f;
    }
    
    CGFloat changeOffset = yOffset+headViewHeight;
    NSLog(@"%f",changeOffset);
    if (changeOffset > 1) {
        CGFloat offset = changeOffset;
        CGFloat alpha = 1 - ((64 - offset) / 64);
        [self.navigationController.navigationBar lt_setBackgroundColor:[[utils getThemeColor] colorWithAlphaComponent:alpha]];
        
        
    } else {
        [self.navigationController.navigationBar lt_setBackgroundColor:[[utils getThemeColor] colorWithAlphaComponent:0]];
    }
}


@end